package com.atguigu.gmall.product.service.impl;

import com.alibaba.fastjson.JSON;
import com.atguigu.gmall.product.vo.ValueSkuJsonVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.gmall.product.entity.SpuSaleAttr;
import com.atguigu.gmall.product.service.SpuSaleAttrService;
import com.atguigu.gmall.product.mapper.SpuSaleAttrMapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 *
 */
@Service
public class SpuSaleAttrServiceImpl extends ServiceImpl<SpuSaleAttrMapper, SpuSaleAttr>
    implements SpuSaleAttrService{

    @Override
    public List<SpuSaleAttr> getSpuSaleAttrList(Long spuId) {
     List<SpuSaleAttr> spuSaleAttrs  =   baseMapper.getSpuSaleAttrList(spuId);
        return spuSaleAttrs;
    }


    @Override
    public List<SpuSaleAttr> getSpuSaleAttrListOrder(Long spuId,Long skuId) {
        List<SpuSaleAttr> saleAttrs = baseMapper.getSpuSaleAttrListOrder(spuId,skuId);

        return saleAttrs;
    }

    @Override
    public String getValuesSkuJson(Long spuId) {
        List<ValueSkuJsonVo> vos = baseMapper.getValuesSkuJson(spuId);

        Map<String, Long> map = vos.stream()
                .collect(Collectors.toMap((t) -> t.getValueJson(), t -> t.getSkuId()));
        String jsonString = JSON.toJSONString(map);
        return jsonString;
    }
}




